/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaces;

import gestiondeviajes.Conductor;
import gestiondeviajes.Empleado;
import gestiondeviajes.GestionDeViajes;
import gestiondeviajes.Pasajero;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.JOptionPane;

/**
 *
 * @author Luciano HP
 */
public class InterReserva extends javax.swing.JInternalFrame {
    
    GestionDeViajes controladora = new GestionDeViajes();
    
     
   
    public InterReserva() {
        initComponents();
        
        this.cmbEmb.setSelectedIndex(-1);
        this.cmbHora.setSelectedIndex(-1);
        CargarComboEmbarcacion();
        cargarComboHora(); 
            
//        cmbConductor.setSelectedIndex(-1);
//        CargarComboConductor();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtEnt = new javax.swing.JTextField();
        txtPrecio = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cmbHora = new javax.swing.JComboBox();
        btnDisp = new javax.swing.JButton();
        cmbFecha = new datechooser.beans.DateChooserCombo();
        cmbEmb = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtFechaSeleccionada = new javax.swing.JTextField();
        btnPasajero = new javax.swing.JButton();
        cmbConductor = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnCancelar = new javax.swing.JButton();
        btnAgregar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("Registrar Pasajeros:");

        jLabel2.setText("Entrega:");

        jLabel3.setText("Precio:");

        txtEnt.setEnabled(false);

        txtPrecio.setEnabled(false);

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel5.setText("Horario:");

        jLabel6.setText("Fecha:");

        btnDisp.setText("Comprobar Disponibilidad");
        btnDisp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDispActionPerformed(evt);
            }
        });

        try {
            cmbFecha.setDefaultPeriods(new datechooser.model.multiple.PeriodSet(new datechooser.model.multiple.Period(new java.util.GregorianCalendar(2012, 10, 18),
                new java.util.GregorianCalendar(2012, 10, 18))));
    } catch (datechooser.model.exeptions.IncompatibleDataExeption e1) {
        e1.printStackTrace();
    }

    jLabel4.setText("Embarcación:");

    txtFechaSeleccionada.setBackground(new java.awt.Color(204, 204, 255));

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(txtFechaSeleccionada, javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(btnDisp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(cmbEmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cmbFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGap(18, 18, 18)
                    .addComponent(jLabel5)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cmbHora, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addComponent(cmbFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(26, 26, 26)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(cmbEmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addComponent(btnDisp, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
            .addComponent(txtFechaSeleccionada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    btnPasajero.setText("Registro");
    btnPasajero.setEnabled(false);
    btnPasajero.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnPasajeroActionPerformed(evt);
        }
    });

    jLabel8.setText("Conductor:");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(38, 38, 38)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel8)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addGap(2, 2, 2)
                            .addComponent(btnPasajero, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtEnt, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cmbConductor, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE))))))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(btnPasajero))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel8)
                .addComponent(cmbConductor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(20, 20, 20)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtEnt, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtPrecio, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                .addComponent(jLabel3))
            .addGap(24, 24, 24))
    );

    jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    btnCancelar.setText("Cancelar");
    btnCancelar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCancelarActionPerformed(evt);
        }
    });

    btnAgregar.setText("Agregar");
    btnAgregar.setEnabled(false);
    btnAgregar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnAgregarActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addContainerGap(266, Short.MAX_VALUE)
            .addComponent(btnAgregar)
            .addGap(18, 18, 18)
            .addComponent(btnCancelar)
            .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnCancelar)
                .addComponent(btnAgregar))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(18, 18, 18)
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDispActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDispActionPerformed
                    
       
     String diaS=dameDiaReserva();
     String mesS=dameMesReserva();
     String anioS=dameAñoReserva();
     String hora= (String) this.cmbHora.getSelectedItem();
     String fechaReserva=hora+diaS+mesS+anioS;
        this.txtFechaSeleccionada.setText("Fecha Seleccionada " + diaS + "/" + mesS + "/" + anioS);
       
       System.out.println("Fecha Seleccionada " + diaS + "/" + mesS + "/" + anioS);
       
       String barco = seleccionarEmb();
       
       
       
       boolean disp = controladora.disponibilidadEmbarcacion(barco,fechaReserva,hora);
       
      /****************verifica la disponiblilidad de embarcacion para esa fecha*************************/ 
       if(disp){
            this.btnPasajero.setEnabled(true);
            this.txtEnt.setEnabled(true);
            this.btnAgregar.setEnabled(true);
            this.cmbConductor.setEnabled(true);
            
       }else{
           JOptionPane.showMessageDialog(rootPane, "Seleccione otra embarcacion", "Embarcacion NO disponible", JOptionPane.ERROR_MESSAGE);
            }
        
    }//GEN-LAST:event_btnDispActionPerformed

    private void btnPasajeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPasajeroActionPerformed
       
        InterPasajero pasajero = new InterPasajero();
        MenuPrincipal.Escritorio.add(pasajero);
        pasajero.show();
        pasajero.setVisible(true);            
    }//GEN-LAST:event_btnPasajeroActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        int op = JOptionPane.showConfirmDialog(rootPane, "Desea Salir?", "Aviso", 1);

        if (op == 0) {

            this.dispose();
        }
    }//GEN-LAST:event_btnCancelarActionPerformed
    
    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
       
        String diaS=dameDiaReserva();
        String mesS=dameMesReserva();
        String anioS=dameAñoReserva();
        String hora= (String) this.cmbHora.getSelectedItem();
        String fechaReserva=hora+diaS+mesS+anioS;
        String emb = seleccionarEmb();
        String entrega = this.txtEnt.getText();
        Conductor conductor=(Conductor) this.cmbConductor.getSelectedItem();
        int entre = Integer.parseInt(entrega);
        
        

         double pre=0;
         
         if (entre >= 1500) {
           
           this.txtPrecio.setEnabled(true);
           // hay q buscar la lista de pasajeros para q determine el precio total
           int cant=42;
           pre=((cant/10)*100)+entre;
           System.out.println(pre);
        }else{
         JOptionPane.showMessageDialog(rootPane,"Debe abonar mas del 30% del costo total","Error",JOptionPane.ERROR_MESSAGE);
         }
           
      this.txtPrecio.setText("$"+pre);   
      
      String diaR=controladora.diaActual();
      String mesR=controladora.mesActual();
      String anioR=controladora.anioActual();
      String horaR= controladora.horaActual();
      
        String fechaTransaccion= horaR+diaR+mesR+anioR;
        
      
      
      /********** ver donde muestro la lista de pasajeros actual ***************/
      ArrayList<Pasajero> pasajeros=controladora.listaDePasajerosEspecial(hora,fechaReserva);
      ArrayList<Empleado> empleado=controladora.asignarEmpleadosReserva(fechaReserva);     
      
      controladora.registrarReserva(pasajeros,conductor,empleado,emb, entre, pre, fechaReserva, fechaTransaccion);

    }//GEN-LAST:event_btnAgregarActionPerformed
   
    
    
    public String seleccionarEmb(){
    //String nombre = txtnombre.getText().toLowerCase();
    //String estiloselec= cmbEstilos.getSelectedItem().toString();
    //System.out.println(estiloselec);

    String barco= (String) this.cmbEmb.getSelectedItem();
    System.out.println(barco);
    return barco;
    }
      
    
      public void cargarComboHora() {
        this.cmbHora.addItem("13:00");
        this.cmbHora.addItem("19:00");
     }
    
     public void CargarComboEmbarcacion() {
          this.cmbEmb.addItem("Don Vigil");
          this.cmbEmb.addItem("El Laurel");
          
// ************************************************************************* 
//      COPIADO DEL METODO cargarEstilos() QUE ESTA EN LA INTERFASE GRUPO   
//          
//         List<Estilo>dameEstilos= unMultimedio.dameEstilo();
//         for(Estilo unEstilo : dameEstilos){
//           misEstilos.addElement(unEstilo.getNombre());
//           }
//         cmbEstilos.setModel(misEstilos);
//****************************************************************************
// Y para agregar a una variable el estilo seleccionado, para luego registrarlo en la BD
// Se debe llamar al combo y tranformarlo en este caso en Stirng combo.getSelectedItem.toString();
//
//       String estiloselec= cmbEstilos.getSelectedItem().toString();

//  SIEMPRE SE DEBE LLAMAR AL METODO EN ESTE CASO, cargarEstilos(), DEBAJO DE initComponents()
   }
    
    
//     public ArrayList registrarPasajeros() {
//         ArrayList<Pasajero> pasajeros;
//         pasajeros=controladora.registrarPasajeros();
//         return pasajeros;
//    } 
//    
  public String dameDiaReserva() {
      int dia1 = this.cmbFecha.getSelectedDate().get(Calendar.DAY_OF_MONTH);
      String dia2 = Integer.toString(dia1);//convierte de entero a String     
        return (dia2);
     }
    
    public String dameMesReserva(){
        int mes1 = this.cmbFecha.getSelectedDate().get(Calendar.MONTH) + 1;
        String mes2 = Integer.toString(mes1);//convierte de entero a String
        return mes2;
    }
    
    public String dameAñoReserva(){
        int año1 = this.cmbFecha.getSelectedDate().get(Calendar.YEAR);
        String año2 = Integer.toString(año1);//convierte de entero a String
        return año2;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnDisp;
    private javax.swing.JButton btnPasajero;
    private javax.swing.JComboBox cmbConductor;
    private javax.swing.JComboBox cmbEmb;
    private datechooser.beans.DateChooserCombo cmbFecha;
    private javax.swing.JComboBox cmbHora;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField txtEnt;
    private javax.swing.JTextField txtFechaSeleccionada;
    private javax.swing.JTextField txtPrecio;
    // End of variables declaration//GEN-END:variables

    
 
}
